
// Saves options to localStorage.
function save_options() {
	var ahv = document.getElementById("allowhard").checked;
	console.log("ah checked:", ahv, "type=", typeof(ahv));
	localStorage["options.allowhard"] = document.getElementById("allowhard").checked;
	localStorage["options.hinttips"] = document.getElementById("hinttips").checked;
	localStorage["options.hlcross"] = document.getElementById("hlcross").checked;
	localStorage["options.hlerrors"] = document.getElementById("hlerrors").checked;

	// Update status to let user know options were saved.
	var status = document.getElementById("status");
	status.innerHTML = "Options Saved.";
	setTimeout(function() { status.innerHTML = ""; }, 750);
}

// Restores select box state to saved value from localStorage.
function restore_options() {
	var ah = localStorage["options.allowhard"];
	console.log("loading allowhard:", ah, "type:", typeof(ah));
	document.getElementById("allowhard").checked = ("true"==localStorage["options.allowhard"]);
	document.getElementById("hinttips").checked =  ("true"==localStorage["options.hinttips"]);
	document.getElementById("hlcross").checked =   ("true"==localStorage["options.hlcross"]);
	document.getElementById("hlerrors").checked =  ("true"==localStorage["options.hlerrors"]);
}

function add_bookmark() {
	chrome.bookmarks.create({
		"parentId": "1",
		"title": "SUDOKU",
		"url": chrome.extension.getURL("gridmenu.html")
	});
}

document.addEventListener('DOMContentLoaded', function () {
  restore_options();
  document.getElementById("save_options").addEventListener("click", save_options);
  document.getElementById("add_bookmark").addEventListener("click", add_bookmark);
});
